<?php

/** Zend_Controller_Action */
require_once ROOT_PATH . '/library/Soooner/Controller/Action.php';

class SearchController extends Soooner_Controller_Action
{
	private $_modelCategory;
	public function init()
    {
        /* Initialize action controller here */
    	$this->initDzTemplate();
    	//$this->_modelCategory = new Model_Tables_Category();
    }
    public function goAction()
    {
    	$modelDocuments = new Model_Tables_Documents();
    	$modelDocuments->fill();
    	system("/usr/local/coreseek/bin/indexer --all --rotate");
    }
    public function indexAction()
    {
    	$start	= $this->_getParam('start') ;
    	$filename = "/tmp/needflush";
    	if($start)
    	{
	    	if (file_exists($filename)) {
	    		$title = "索引重建中，请不要重复点击！";
		        $info = "索引重建中，重建索引比较消耗系统性能，请不要重复点击！";
	    	}
	    	else
	    	{
	    		file_put_contents("/tmp/needflush","1");
	    		file_put_contents("/tmp/needflush1","1");
	    		$title = "开始重建索引";
	        	$info = "开始重建索引，您现在可以离开该页面了！";
	    	}
    	}
    	else
    	{
    		if (file_exists($filename)) {
	    		$title = "索引重建中，请不要重复点击！";
		        $info = "索引重建中，重建索引比较消耗系统性能，请不要重复点击！";
	    	}
	    	else
	    	{
	    		$title = "开始重建索引";
	        	$info = "<a href='/search/index/start/1'>开始重建索引</a>";
	    	}
    	}
        include $this->_dzTemplate->getFile( 'main.html' );
    }
    
	public function flushepgAction()
    {
    	$start	= $this->_getParam('start') ;
    	$filename = "/tmp/epgneedflush";
    	if($start)
    	{
	    	if (file_exists($filename)) {
	    		$title = "节目单更新中，请不要重复点击！";
		        $info = "节目单更新中，节目单更新比较消耗系统性能，请不要重复点击！";
	    	}
	    	else
	    	{
	    		file_put_contents("/tmp/epgneedflush","1");
	    		file_put_contents("/tmp/epgneedflush1","1");
	    		$title = "开始更新节目单";
	        	$info = "开始更新节目单，您现在可以离开该页面了！";
	    	}
    	}
    	else
    	{
    		if (file_exists($filename)) {
	    		$title = "节目单更新中，请不要重复点击！";
		        $info = "节目单更新中，节目单更新比较消耗系统性能，请不要重复点击！";
	    	}
	    	else
	    	{
	    		$title = "开始更新节目单";
	        	$info = "<a href='/search/flushepg/start/1'>开始更新节目单</a>";
	    	}
    	}
        include $this->_dzTemplate->getFile( 'main.html' );
    }
    
	public function createxmlAction()
    {
    	$start	= $this->_getParam('start') ;
    	$filename = "/tmp/needcreateXml";
    	if($start)
    	{
	    	if (file_exists($filename)) {
	    		$title = "页面重新生成中，请不要重复点击！";
		        $info = "页面重新生成中，请不要重复点击！";
	    	}
	    	else
	    	{
	    		//file_put_contents("/tmp/needcreateXml","1");
	    		//file_put_contents("/tmp/needcreateXml1","1");
	    		//print_r($_POST);exit;
	    		$index = count($_POST["index"]);
	    		$epg = count($_POST["epg"]);
	    		$cat = 0;
	    		if($_POST["cat"])
	    			$cat = implode(",",$_POST["cat"]);
	    		$v = "$index|$epg|$cat";
	    		file_put_contents("/tmp/needcreateXml","$v");
	    		file_put_contents("/tmp/needcreateXml1","$v");
	    		$title = "开始生成页面";
	        	$info = "开始生成页面，您现在可以离开该页面了！";
	    	}
	    	include $this->_dzTemplate->getFile( 'main.html' );
    	}
    	else
    	{
    		if (file_exists($filename)) {
	    		$title = "页面重新生成中，请不要重复点击！";
		        $info = "页面重新生成中，请不要重复点击！";
		        include $this->_dzTemplate->getFile( 'main.html' );
	    	}
	    	else
	    	{
	    		$title = "开始生成静态页面";
	        	//$catlist = $this->_modelCategory->getAllCategoryNameList();
	        	$index = array("1"=>"首页");
	        	$epg = array("1"=>"节目单");
	    		$info = "请选择需要重新生成的内容</a>";
	    		include $this->_dzTemplate->getFile( 'mainStatic.html' );
	    	}
    	}
    }
}
